spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......

您所在的位置:网站首页 does 的意思 spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......

spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......

#spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......| 来源: 网络整理| 查看: 265

下面这几行代码大家应该都很熟悉,就是 Spring 的 "Hello World"。

 那么我们在运行这个 main方法可能会遇到【报错】:Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not exist......就像这样:

大概意思就是没有找到 spring.xml 这个配置文件,仔细看 spring.xml 是在 resource 目录下,貌似是没啥问题

再展开看下 target 目录发现了问题所在,这是因为在 Idea 中,编译器只会把 src/main/java 也就是源代码目录下的 .java 文件编译成 .class 文件然后放到 target 目录中,其他的默认不会。

 这里我们只需要将 spring.xml 文件复制到 target/classes/ 下即可解决

然后再运行试一下,OK啦。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3